#include <bits/stdc++.h>
using namespace std;

class Solution {    
private:
    static const int N=100000;
    int c[N+4000];
    void add(int x,int d) {
        x += N;
        for (int i=x;i<N+4000;i+=i&(-i)) {
            c[i] += d;
        }
    }
    int get(int x) {
        x += N;
        int res=0;
        for (int i=x;i;i-=i&(-i)) {
            res += c[i];
        }
        return res;
    }
public:
    vector<int> numsGame(vector<int>& nums) {
        int mod = 1000000007;
        int n = nums.size();
        using ll = long long;
        vector<ll> res;
        res.push_back(0);
        add(nums[0]-0, 1);
        int last = nums[0];
        for (int i=1;i<n;i++) {
            // printf("%d %d\n", i, last);
            ++last;
            if (last>=nums[i]) {
                ll now = res.back() + last-nums[i];
                int leq = get(last-1-i);
                while (last-1 >= nums[i] && (i-leq)*(1)+(leq)*(-1) -1 <= 0) {
                    now = now + (i-leq)*(1)+(leq)*(-1) -1;
                    --last;
                    leq = get(last-1-i);
                }
                res.push_back(now);
            } else {
                ll now = res.back() + nums[i]-last;
                int leq = get(last-i);
                while (last+1 <= nums[i] && (i-leq)*(-1)+(leq)*(1) -1 <= 0) {
                    now = now+ (i-leq)*(-1)+(leq)*(1) -1;
                    ++last;
                    leq = get(last-i);
                }
                res.push_back(now);
            }
            add(nums[i]-i, 1);
        }
        vector<int> mres;
        for (auto x : res) {
            mres.push_back(x % mod);
        }
        return mres;
    }
};
int main(){
    Solution s;
    vector<int> v{3,4,5,1,6,7};
    vector<int> ans=s.numsGame(v);
    for(int i=0;i<ans.size();i++){
        cout << ans[i] << " ";
    }cout <<endl;


    return 0;
}